const express = require('express')
const router = express.Router()
const multer = require('multer')
const path = require('path')
const expressJoi = require('@escook/express-joi')

const rank_handler = require('../router_handler/rank')
const {update_cartonlike_schema, add_cartoninfo_schema} = require('../schema/rank')

let myFileName = ''
const upload = multer({
  dest: path.join(__dirname, '../uploads'),
  filename: (req,file,cb) => {
    myFileName = `${file.originalname}.${file.originalname.split('.').splice(-1)}`
    cb(null, myFileName)
  }
})

// 动漫排行榜列表
router.get('/cartonranklist', rank_handler.cartonRankList)
// 游戏排行榜列表
router.get('/gameranklist', rank_handler.gameRankList)
// 动漫排行榜点赞功能
router.post('/addcartonlike', expressJoi(update_cartonlike_schema), rank_handler.addCartonLike)
// 动漫排行榜取消点赞功能
router.post('/cancelcartonlike', expressJoi(update_cartonlike_schema), rank_handler.cancelCartonLike)
// 游戏排行榜点赞功能
router.post('/addgamelike', expressJoi(update_cartonlike_schema), rank_handler.addGameLike)
// 游戏排行榜取消点赞功能
router.post('/cancelgamelike', expressJoi(update_cartonlike_schema), rank_handler.cancelGameLike)

// 添加动漫排行榜信息
router.post('/addcartoninfo', upload.single('poster'), expressJoi(add_cartoninfo_schema), rank_handler.addCartonInfo)
// 添加游戏排行榜信息
router.post('/addgameinfo', upload.single('poster'), expressJoi(add_cartoninfo_schema), rank_handler.addGameInfo)
// 删除动漫排行榜信息
router.post('/delcartonrank',expressJoi(update_cartonlike_schema), rank_handler.delCartonInfo)
// 删除游戏排行榜信息
router.post('/delgamerank',expressJoi(update_cartonlike_schema), rank_handler.delGameInfo)

module.exports = router